//--------------------------------------------------------------
//
// Qizhi Zhang 
// ezhung@gmail.com
// http://www.moorwind.com
//
//--------------------------------------------------------------
package reader.controller
{
	import org.puremvc.as3.multicore.interfaces.ICommand;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.command.SimpleCommand;
	
	import reader.ApplicationFacade;
	import reader.core.ReaderModelLocator;
	import reader.model.IDataProxy;
	import reader.model.IDraftProxy;
	import reader.model.IServiceProxy;
	import reader.model.IUserProxy;

	public class DeleteAccountCommand extends SimpleCommand implements ICommand
	{
		//////////////////////////////////////////////////////////////////////////////
		//methods
	
		override public function execute(notification:INotification):void
		{
			var dataProxy:IDataProxy = facade.retrieveProxy(ReaderModelLocator.instance.sqliteProxyFactory.dataProxyName) as IDataProxy;
			dataProxy.deleteAccount();
			var serviceProxy:IServiceProxy = facade.retrieveProxy(ReaderModelLocator.instance.sqliteProxyFactory.serviceProxyName) as IServiceProxy;
			serviceProxy.deleteAccount();
			var userProxy:IUserProxy = facade.retrieveProxy(ReaderModelLocator.instance.sqliteProxyFactory.userProxyName) as IUserProxy;
			userProxy.deleteAccount();
			var draftProxy:IDraftProxy = facade.retrieveProxy(ReaderModelLocator.instance.sqliteProxyFactory.draftProxyName) as IDraftProxy;
			if(!draftProxy)
			{
				facade.registerProxy(ReaderModelLocator.instance.sqliteProxyFactory.draftProxy);
				draftProxy = facade.retrieveProxy(ReaderModelLocator.instance.sqliteProxyFactory.draftProxyName) as IDraftProxy;
			}
			draftProxy.deleteAccount();
			sendNotification(ApplicationFacade.LOGOUT);
		}
		
		
	}
}